﻿Public Class DcomoSeEntero

    Public Shared Function SeleccionarTodo(ByVal descEmpresa As String) As List(Of EcomoSeEntero)
        Dim seEnteros As List(Of EcomoSeEntero) = Nothing

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_comoSeEntero_sel", cn)
                cmd.CommandType = CommandType.StoredProcedure
                Try
                    cn.Open()
                    Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.CloseConnection)
                        If dr.HasRows Then
                            seEnteros = New List(Of EcomoSeEntero)
                            Dim seEntero As EcomoSeEntero = Nothing
                            Do While dr.Read
                                seEntero = New EcomoSeEntero( _
                                    dr.GetInt32(dr.GetOrdinal("idComoSeEntero")), _
                                    dr.GetString(dr.GetOrdinal("descComoseEntero")), _
                                    dr.GetString(dr.GetOrdinal("estado")))
                                seEnteros.Add(seEntero)
                            Loop
                            dr.Close()
                        End If
                    End Using
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return seEnteros
    End Function
    Public Shared Function SeleccionarXEstado(ByVal descEmpresa As String) As List(Of EcomoSeEntero)
        Dim seEnteros As List(Of EcomoSeEntero) = Nothing

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_comoSeEntero_selXEstado", cn)
                cmd.CommandType = CommandType.StoredProcedure
                Try
                    cn.Open()
                    Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.CloseConnection)
                        If dr.HasRows Then
                            seEnteros = New List(Of EcomoSeEntero)
                            Dim seEntero As EcomoSeEntero = Nothing
                            Do While dr.Read
                                seEntero = New EcomoSeEntero( _
                                    dr.GetInt32(dr.GetOrdinal("idComoSeEntero")), _
                                    dr.GetString(dr.GetOrdinal("descComoseEntero")), _
                                    dr.GetString(dr.GetOrdinal("estado")))
                                seEnteros.Add(seEntero)
                            Loop
                            dr.Close()
                        End If
                    End Using
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return seEnteros
    End Function
    Public Shared Function Añadir(ByVal descEmpresa As String, ByVal pseEntero As EcomoSeEntero) As Boolean
        Dim resultado As Boolean = False

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_comoSeEntero_add", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@descComoseEntero", SqlDbType.VarChar, 55).Value = pseEntero.descComoseEntero
                cmd.Parameters.Add("@idUsuario", SqlDbType.Int).Value = pseEntero.idUsuario
                Try
                    cn.Open()
                    cmd.ExecuteNonQuery()
                    resultado = True
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return resultado
    End Function
    Public Shared Function Editar(ByVal descEmpresa As String, ByVal pseEntero As EcomoSeEntero) As Boolean
        Dim resultado As Boolean = False

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_comoSeEntero_edit", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idComoSeEntero", SqlDbType.Int).Value = pseEntero.idComoSeEntero
                cmd.Parameters.Add("@descComoseEntero", SqlDbType.VarChar, 55).Value = pseEntero.descComoseEntero
                cmd.Parameters.Add("@estado", SqlDbType.Char, 1).Value = pseEntero.estado
                cmd.Parameters.Add("@idUsuario", SqlDbType.Int).Value = pseEntero.idUsuario
                Try
                    cn.Open()
                    cmd.ExecuteNonQuery()
                    resultado = True
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return resultado
    End Function
    Public Shared Function Eliminar(ByVal descEmpresa As String, ByVal pseEntero As EcomoSeEntero) As Boolean
        Dim resultado As Boolean = False

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_comoSeEntero_del", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idComoSeEntero", SqlDbType.Int).Value = pseEntero.idComoSeEntero
                cmd.Parameters.Add("@idUsuario", SqlDbType.Int).Value = pseEntero.idUsuario
                Try
                    cn.Open()
                    cmd.ExecuteNonQuery()
                    resultado = True
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return resultado
    End Function

    '******* RptGerenciales xModelos *******'
    Public Shared Function rptGerenciales_xComoSeEntero(ByVal descEmpresa As String, ByVal rptGerencial As EproformaCabecera) As List(Of EcomoSeEntero)
        Dim comoSeEnteros As List(Of EcomoSeEntero) = Nothing

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_rptGerencial_xComoSeEntero", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idProyecto", SqlDbType.Int).Value = rptGerencial.idProyecto
                cmd.Parameters.Add("@idEtapa", SqlDbType.Int).Value = rptGerencial.idEtapa
                cmd.Parameters.Add("@FechaInicial", SqlDbType.Char, 10).Value = rptGerencial.fchInicio
                cmd.Parameters.Add("@FechaFinal", SqlDbType.Char, 10).Value = rptGerencial.fchFin
                Try
                    cn.Open()
                    Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.CloseConnection)
                        If dr.HasRows Then
                            comoSeEnteros = New List(Of EcomoSeEntero)
                            Dim comoSeEntero As EcomoSeEntero = Nothing
                            Do While dr.Read
                                comoSeEntero = New EcomoSeEntero( _
                                    dr.GetInt32(dr.GetOrdinal("idComoSeEntero")), _
                                    dr.GetString(dr.GetOrdinal("descComoSeEntero")), _
                                    dr.GetInt32(dr.GetOrdinal("cantidad")), _
                                    dr.GetDecimal(dr.GetOrdinal("porcentaje")))
                                comoSeEnteros.Add(comoSeEntero)
                            Loop
                            dr.Close()
                        End If
                    End Using
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return comoSeEnteros
    End Function

End Class
